package com.ui.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.base.ex.ExBaseFragment;
import com.manager.ListFragment;
import com.ui.contract.MainContract;
import com.ui.main.R;
import com.ui.model.MainModel;
import com.ui.presenter.MainPresenter;
import com.util.helper.FragmentAdapter;
import com.view.viewholder.ArticleItemVH;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.Bind;
import rx.Observable;

/**
 * @Description
 * @Author luxiao418
 * @Email luxiao418@pingan.com.cn
 * @Date 16/8/11 17:47
 * @Version v2.6.0
 */
public class MainFragment extends ExBaseFragment<MainPresenter,MainModel> implements MainContract.View{
    @Bind(R.id.main_viewpager)
    ViewPager mMainViewpager;
    @Bind(R.id.main_tablayout)
    TabLayout mMainTablayout;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {}

    @Override
    public void showTabList(String[] tabList) {
        List<Fragment> fragments = new ArrayList<>();
        //初次使用lambda表达式,想fragments集合中添加fragment
        Observable.from(tabList).subscribe(tab -> fragments.add(ListFragment.newInstance(ArticleItemVH.class, tab)));
        mMainViewpager.setAdapter(new FragmentAdapter(getChildFragmentManager(), fragments, Arrays.asList(tabList)));
        mMainTablayout.setupWithViewPager(mMainViewpager);
        mMainTablayout.setTabsFromPagerAdapter(mMainViewpager.getAdapter());
    }
}
